﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data.Linq.Mapping;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;

namespace PasswordManager.Src.DAO
{
    [Table]
    public class AppSetting: INotifyPropertyChanged
    {
        [Column(IsPrimaryKey=true,CanBeNull=false)]
        public int Id { get; set; }
        private string _language;
        [Column(CanBeNull=false)]
        public string Language
        {
            get
            {
                return _language;
            }
            set
            {
                if (_language != value)
                {
                    _language = value;
                    NotifyPropertyChanged("Language");
                }
            }
        }
        public static void InitLanguage()
        {
            PasswordManagerDataContext db = new PasswordManagerDataContext();
            Thread.CurrentThread.CurrentCulture = new CultureInfo(db.AppSettinges.First().Language);
            Thread.CurrentThread.CurrentUICulture = Thread.CurrentThread.CurrentCulture;
        }

        #region INotifyPropertyChanged Members

        public event PropertyChangedEventHandler PropertyChanged;
        private void NotifyPropertyChanged(String propertyName)
        {
            PropertyChangedEventHandler handler = PropertyChanged;
            if (null != handler)
            {
                handler(this, new PropertyChangedEventArgs(propertyName));
            }
        }
        #endregion
    }
}
